package com.mdb.open.trade.service.trade;


/*
* Copyright (C), 2017-2019 澳发科技(MDB)
* FileName: TfTradeFileTransportInfoService.java
* Author:   you.yichao
* Date:     2019-10-11
* History:
* <author>          <time>          <version>          <desc>
* you.yichao         2019-10-11          V1.00             代码生成器初始生成代码
* -----------------------------------------------------------
* 作者姓名           修改时间           版本号            描述
*/


import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.mdb.bc.api.data.ListResultEx;
import com.mdb.bc.api.data.ResultEx;
import com.mdb.bc.database.mybatisplus.SuperService;
import com.mdb.open.trade.common.MdbDataSource;
import com.mdb.open.trade.domain.bo.trade.SaveTradeFileTransportInfoBo;
import com.mdb.open.trade.domain.bo.trade.UpdateTradeFileTransportInfoBo;
import com.mdb.open.trade.domain.po.trade.TradeFileTransportInfo;
import com.mdb.open.trade.mapper.trade.TfTradeFileTransportInfoMapper;
import org.springframework.stereotype.Service;

/**
 * 类描述：
 *  贸易档案运输信息表 服务类
 *
 * @author you.yichao
 * @date 2019-10-11
 */
@Service
@DS(MdbDataSource.TRADE)
public class TfTradeFileTransportInfoService extends SuperService<TfTradeFileTransportInfoMapper, TradeFileTransportInfo> {

    public ResultEx<TradeFileTransportInfo> getInfoByNo(String tradeFileNo) {
        return ResultEx.ok(this.baseMapper.selectOne(new LambdaQueryWrapper<TradeFileTransportInfo>()
                .eq(TradeFileTransportInfo::getTradeFileNo, tradeFileNo)));
    }

    public ResultEx<TradeFileTransportInfo> getInfoByNo(String tradeFileNo, String tradeFileCustomsNo) {
        return ResultEx.ok(this.baseMapper.selectOne(new LambdaQueryWrapper<TradeFileTransportInfo>()
                .eq(TradeFileTransportInfo::getTradeFileNo, tradeFileNo)
                .eq(TradeFileTransportInfo::getTradeFileCustomsNo, tradeFileCustomsNo)));
    }

    public ListResultEx<TradeFileTransportInfo> queryInfoByNo(String tradeFileNo) {
        return ListResultEx.ok(this.baseMapper.selectList(new LambdaQueryWrapper<TradeFileTransportInfo>()
                .eq(TradeFileTransportInfo::getTradeFileNo, tradeFileNo)
                .eq(TradeFileTransportInfo::isDeleted, false)));
    }

    public ResultEx saveTransportInfo(SaveTradeFileTransportInfoBo bo) {

        TradeFileTransportInfo saveTransportInfo = new TradeFileTransportInfo();
        saveTransportInfo.setTradeFileNo(bo.getTradeFileNo());
        saveTransportInfo.setCustomsNo(bo.getCustomsNo());
        saveTransportInfo.setTradeFileCustomsNo(bo.getTradeFileCustomsNo());
        saveTransportInfo.setBusinessNo(bo.getBusinessNo());
        saveTransportInfo.setCustomerCode(bo.getCustomerCode());
        saveTransportInfo.setMcustomerCode(bo.getMcustomerCode());
        saveTransportInfo.setCustomerName(bo.getCustomerName());
        saveTransportInfo.setMerchantNo(bo.getMerchantNo());
        saveTransportInfo.setMerchantName(bo.getMerchantName());
        saveTransportInfo.setLadingBillNo(bo.getLadingBillNo());
        saveTransportInfo.setContainerNo(bo.getContainerNo());
        saveTransportInfo.setShipper(bo.getShipper());
        saveTransportInfo.setReceiverCnName(bo.getReceiverCnName());
        saveTransportInfo.setReceiverEnName(bo.getReceiverEnName());
        saveTransportInfo.setShipLoadTime(bo.getShipLoadTime());
        saveTransportInfo.setReceiverCountry(bo.getReceiverCountry());
        saveTransportInfo.setTransportName(bo.getTransportName());
        saveTransportInfo.setTransportType(bo.getTransportType());
        saveTransportInfo.setSourceType(bo.getSourceType());

        int count = this.baseMapper.insert(saveTransportInfo);
        if (count != 1) {
            return ResultEx.fail();
        }
        return ResultEx.ok();
    }

    public ResultEx updateTransportInfo(UpdateTradeFileTransportInfoBo bo) {

        TradeFileTransportInfo updateTransportInfo = new TradeFileTransportInfo();
        updateTransportInfo.setCustomsNo(bo.getCustomsNo());
        updateTransportInfo.setLadingBillNo(bo.getLadingBillNo());
        updateTransportInfo.setContainerNo(bo.getContainerNo());
        updateTransportInfo.setShipper(bo.getShipper());
        updateTransportInfo.setReceiverCnName(bo.getReceiverCnName());
        updateTransportInfo.setReceiverEnName(bo.getReceiverEnName());
        updateTransportInfo.setShipLoadTime(bo.getShipLoadTime());
        updateTransportInfo.setReceiverCountry(bo.getReceiverCountry());
        updateTransportInfo.setTransportName(bo.getTransportName());
        updateTransportInfo.setTransportType(bo.getTransportType());

        LambdaUpdateWrapper<TradeFileTransportInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(TradeFileTransportInfo::getTradeFileNo, bo.getTradeFileNo());
        updateWrapper.eq(TradeFileTransportInfo::getTradeFileCustomsNo, bo.getTradeFileCustomsNo());

        int count = this.baseMapper.update(updateTransportInfo, updateWrapper);
        if (count != 1) {
            return ResultEx.fail();
        }

        return ResultEx.ok();
    }


}
